﻿using PTop.Code;
using PTop.Domain.Entity.Article;
using PTop.Domain.IRepository.Article;
using PTop.Repository.Article;
using System.Collections.Generic;

namespace PTop.Application.Article
{
    /// <summary>
    /// 文章标签
    /// </summary>	
    public class TagApp
    {
        private ITagRepository service = new TagRepository();

        public List<TagEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<TagEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Name.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public List<TagEntity> GetValidList()
        {
            var expression = ExtLinq.True<TagEntity>();
            expression = expression.And(t => t.F_State == 1);
            return service.FindList(expression,
                new Pagination
                {
                    page = 1,
                    rows = 10000,
                    sidx = "F_CreatorTime desc",
                    sord = "asc"
                });
        }

        public List<TagEntity> GetListByArticle(string articleId)
        {
            return service.FindListByArticle(articleId);
        }

        public TagEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void Delete(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }

        public void SubmitForm(TagEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
                service.Update(entity);
            }
            else
            {
                entity.Create();
                service.Insert(entity);
            }
        }

    }
}